package com.bo.Service.Impl;


import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bo.Dao.ProductDao;
import com.bo.Entity.MyImage;
import com.bo.Entity.MyPage;
import com.bo.Entity.Product;
import com.bo.Service.ProductService;


@Service
public class ProductServiceImpl implements ProductService{
	
	 @Autowired
	 private ProductDao productDao;
	 

	 @Transactional(readOnly=true)
     public boolean createPage(MyPage<Product> myPage){
		   
		  try{
			  
			  long rowCount=productDao.count(myPage.getCompanyId());

			  myPage.setRowCount((int)rowCount);
			  
			  List<Product> list=productDao.createPage(myPage);
			  
			  myPage.setList(list);
			  
		   return true;
		  }catch(Exception e){
			  e.printStackTrace();
			  return false;
		  }
     }
     
	 @Transactional(readOnly=true)
     public List<Product> getAllProduct(int companyId){
    	 
    	 return this.productDao.getAllProduct(companyId);
     }
     
	 @Transactional(readOnly=true)
     public Product getProduct(int id){
    	 
    	 return this.productDao.getProduct(id);
     }
     
	 @Transactional
     public boolean save(Product product){
    	 
    	 int num=this.productDao.save(product);
    	 
    	 if(num>0)
    		 return true;
    	 else
    		 return false;
     }
	
	 
	 @Transactional
     public boolean update(Product product){
    	 
    	 int num=this.productDao.update(product);
    	 
    	 if(num>0)
    		 return true;
    	 else
    		 return false;
     }
     
	 
	 @Transactional
     public boolean delete(int id){
    	 
    	 int num=this.productDao.delete(id);
    	 
    	 if(num>0)
    		 return true;
    	 else 
    		 return false;
     }
	 
	 
     
	 @Transactional(readOnly=true)
     public void getImage(int id, MyImage image){
    	 
    	 try{
 			
  		   productDao.getImage(id, image);
  		   
  		}catch(EmptyResultDataAccessException e){
  			
  		}
     }
}
